package vip.ola.manage.utils;

import cn.hutool.core.convert.NumberChineseFormatter;
import com.deepoove.poi.XWPFTemplate;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @ClassName PdfUtils
 * @Version 1.0
 **/
public class PdfUtils {
    public static void main(String[] args) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("flowNo", "2023080200000000001");
        params.put("txnDate", "20230802");
        params.put("payeeName", "张三");
        params.put("payeeNo", "123456");
        params.put("payeeBankName", "中国银行");
        SimpleDateFormat smf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = smf.format( new Date());
        params.put("payTime", time);
        String amount ="10001";
        params.put("amount",amount);
        String amountBig = NumberChineseFormatter.format(Double.valueOf(amount), true, true);
        params.put("amountBig", amountBig);
   //     Resource resource = new ClassPathResource("templates_report/ypl.docx");
        File file = new File("D:\\ypl.docx");
        // 数据填充
        XWPFTemplate template = XWPFTemplate.compile(file).render(params);

        String docOutPath = "D:\\ypl\\2023080200000000001-ypl.docx";
        OutputStream outputStream = new FileOutputStream(docOutPath);
        template.write(outputStream);
//        final byte[] data = FreeMarkUtils.createDocx2Pdf(params, "D:\\ypl.docx");
    }
}
